package com.kevin.mybatis.leecode;


/**
 * 有序数组原地删除复杂度 O(1)
 */
public class 删除排序数组的重复项 {
    public static void main(String[] args) {

        System.out.println(removeDuplicates(new int[]{0, 1, 1, 1, 2, 2, 3, 4, 7, 89}));
    }

    public static int removeDuplicates(int[] nums) {

        if (nums.length == 0) {
            return 0;
        }
        int i = 0;
        for (int j = 1; j < nums.length; j++) {
            if (nums[j] != nums[i]) {
                i++;
                nums[i] = nums[j];
            }

        }
        return i + 1;
    }


}
